package com.example.administrator.szb.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.szb.R;


/**
 * Created by Administrator on 2017/9/22/022.
 */

public class MyTextView extends RelativeLayout{
    ImageView imageView;
    TextView textView;
    private String titleText;
    public MyTextView(Context context) {
        super(context);
        initView(context,null);
    }

    public MyTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context,attrs);
    }

    public MyTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context,attrs);
    }

    private void initView(Context context,AttributeSet attrs) {
        TypedArray mTypedArray=context.obtainStyledAttributes(attrs,R.styleable.MyView);
        titleText = mTypedArray.getString(R.styleable.MyView_title_text);
        LayoutInflater.from(context).inflate(R.layout.view_my__button, this, true);
        imageView = (ImageView) findViewById(R.id.imageView4);
        textView = (TextView) findViewById(R.id.textView11);
        mTypedArray.recycle();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        textView.setText(titleText);
    }

    public void setTitle(String titlename) {
        if (!TextUtils.isEmpty(titlename)) {
            textView.setText(titlename);
        }
    }

    public void setListener(OnClickListener onClickListener) {
        imageView.setOnClickListener(onClickListener);
    }
}
